import ServiceBase from '../base';
import {BoxProfileProxy, BoxProxy} from '../proxies/box-proxy';
import * as proxy from '../proxy';
import {UserPageProxy} from '../proxies/user-page-proxy';
import {UserModelProxy} from '../proxies/user-model-proxy';

class BoxService extends ServiceBase {
    public getBoxInfo = () => {
        const promise = super.get({
            url: '/box',
        });
        return proxy.httpResultProxy(promise, BoxProxy);
    };
    public updateBoxInfo = (data) => {
        const promise = super.put({
            url: '/box',
            data,
        });
        return proxy.httpResultProxy(promise, BoxProxy);
    };
    public getBoxProfile = () => {
        const promise = super.getWithoutToken({
            url: '/box/profile',
        });
        return proxy.httpResultProxy(promise, BoxProfileProxy);
    };
    // 创建发票
    public postInvoice = (data) => {
        const promise = super.post({
            url: '/invoice',
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // 删除发票
    public deleteInvoice = (data) => {
        const promise = super.delete({
            url: `/invoice/${data.invoiceId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    // 更新发票
    public putInvoice = (data) => {
        const promise = super.put({
            url: `/invoice/${data.invoiceId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // 获取发票列表
    public getInvoiceList = () => {
        const promise = super.get({
            url: '/invoice',
        });
        return proxy.httpResultProxy(promise);
    };
    // 获取单个发票
    public getInvoiceById = (data) => {
        const promise = super.get({
            url: `/invoice/${data.invoiceId}`,
        });
        return proxy.httpResultProxy(promise);
    };

    // 获取用户订单列表
    public getUserOrderList = () => {
        const promise = super.get({
            url: '/order',
        });
        return proxy.httpResultProxy(promise);
    };

    /**
     * @获取系统所有用户的订单，供系统管理员使用
     * @memberof BoxService
     */
    public getAllUserOrderList = (data) => {
        const promise = super.get({
            url: '/order/all',
            params: data,
        });
        return proxy.httpResultProxy(promise);
    };

    // GET 搜索用户订单
    public searchOrders = (data) => {
        const promise = super.get({
            url: '/order/search',
            params: data,
        });
        return proxy.httpResultProxy(promise);
    }

    /**
     * @获取指定ID的用户订单
     * @date 2018-09-16
     * @memberof BoxService
     */
    public getUserOrder = (data: any) => {
        const promise = super.get({
            url: `/order/${data.orderId}`,
        });
        return proxy.httpResultProxy(promise);
    };

    // 更新用户订单
    public updateUserOrder = (data: any) => {
        const promise = super.put({
            url: `/order/${data.orderId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    /**
     * 创建订单接口
     * createOrder
     */
    public createOrder = (data: any) => {
        const promise = super.post({
            url: '/order',
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    public getOrderPrice = (data: any) => {
        const promise = super.post({
            url: '/order/price',
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };


    /**
     * 获取组织成员的邀请信息,默认根据邀请数倒叙排序
     * getInviteInfo
     */
    public getAllInviteInfo = (data: any) => {
        const promise = super.get({
            url: `/stats/accounts/${data.accountId}/inviteinfo`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // 获取指定组织成员的邀请信息
    public getDesignatedInviteInfo = (data: any) => {
        const promise = super.get({
            url: `/stats/accounts/${data.accountId}/members/${data.memberId}/inviteinfo`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // POST /myspace/contacts 添加联系人
    public addContacts = (data) => {
        const promise = super.post({
            url: '/myspace/contacts',
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // GET /myspace/contacts/support 获取技术支持
    public getContactsSupport = () => {
        const promise = super.get({
            url: '/myspace/contacts/support',
        });
        return proxy.httpResultProxy(promise);
    };

    // GET /userinfo 获取用户信息，以判断是否是合约部管理员
    public getContractRole = () => {
        const promise = super.get({
            url: '/userinfo',
        });
        return proxy.httpResultProxy(promise);
    }

    // POST /users 用户注册
    public postSignUpUser = (data) => {
        const promise = super.post({
            url: '/users',
            data,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    };
    public postSignUpUserWithoutToken = (data) => {
        let promise = super.postWithoutToken({
            url: '/users',
            data,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    }

    // GET 获取用户的分页信息
    public getUsersPaging = (data) => {
        let promise = super.get({
            url: `/users`,
            params: data,
        });
        return proxy.httpResultProxy(promise, UserPageProxy);
    };
}

export {BoxService};
